package com.threegold.listview.common;

import com.threegold.listview.LoadMoreView;
import com.threegold.listview.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

public class CommonLoadMoreView extends LoadMoreView {

    private CircleLoadingView progressView;
    private Text loadingText;

    private String loadingString = "努力加载中";
    private String noMoreString = "------已经到底了------";

    public CommonLoadMoreView(Context context, ComponentContainer parent) {
        super(context, parent);
        showLoadingLayout();
    }

    @Override
    protected void showNoMoreLayout() {
        progressView.setVisibility(Component.HIDE);
        loadingText.setText(noMoreString);
    }

    @Override
    protected void showLoadingLayout() {
        progressView.setVisibility(Component.VISIBLE);
        loadingText.setText(loadingString);
    }

    public void setNoMoreString(String noMoreString) {
        this.noMoreString = noMoreString;
    }

    public void setLoadingString(String loadingString) {
        this.loadingString = loadingString;
        loadingText.setText(loadingString);
    }

    public CircleLoadingView getProgressView() {
        return progressView;
    }

    public Text getLoadingText() {
        return loadingText;
    }

    @Override
    protected Component initLoadMoreLayout(Context context, ComponentContainer parent) {
        Component root = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_common_load_more, parent, false);
        progressView = (CircleLoadingView) root.findComponentById(ResourceTable.Id_progressView);
        loadingText = (Text) root.findComponentById(ResourceTable.Id_loadingText);
        return root;
    }


}
